/**$Licence:
 *   Use this however/wherever you like, just don't blame me if it breaks anything.
 *   Copyright (C) 2008 - 2012 xingsheng.zhu@gmail.com All rights reserved.
 */
package com.blazemina.mina;

import java.net.SocketAddress;

import org.apache.mina.core.session.IoSession;

import com.blazemina.message.Message;

/**
 * @author JackChu
 * @version 1.0.0 2012-1-13 下午3:18:15
 */
public class SocketSession implements Session{

	private IoSession ioSession;
	
	public SocketSession(IoSession ioSession){
		this.ioSession = ioSession;
	}
	
	
	@Override
	public long getId() {
		return ioSession.getId();
	}

	@Override
	public void send(Message message) {
		ioSession.write(new Object[]{message.getCommand(),message.getData()});
	}

	@Override
	public void close(boolean immediately) {
		ioSession.close(immediately);
	}

	@Override
	public SocketAddress getRemoteAddress() {
		return ioSession.getRemoteAddress();
	}

	@Override
	public Object setAttribute(Object key, Object value) {
		return ioSession.setAttribute(key,value);
	}

	@Override
	public Object getAttribute(Object key) {
		return ioSession.getAttribute(key);
	}


	@Override
	public boolean isConnected() {
		return ioSession.isConnected();
	}


	/* (non-Javadoc)
	 * @see com.blazemina.mina.Session#isClosing()
	 */
	@Override
	public boolean isClosing() {
		return ioSession.isClosing();
	}


	@Override
	public void setIdleTime(int seconds) {
		ioSession.getConfig().setBothIdleTime(seconds);
		
	}

}
